package com.bawei.library_network.interceptor

import com.blankj.utilcode.util.NetworkUtils
import okhttp3.CacheControl
import okhttp3.Interceptor
import okhttp3.Response
import java.util.concurrent.TimeUnit

/**

 * @Author : ytx

 * @Time : On 2023/5/19 16:29

 * @Description : RequstCacheInterceptor 所有的api请求都会缓存 通过addNetWorkInterceptor？？
 * 因为通过addNetWorkInterceptor发生网络请求之后，这样就会缓存数据

 */
class ResponseCacheInterceptor:Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val response: Response = chain.proceed(chain.request())
        val cacheControl = CacheControl.Builder()
            .maxAge(30, TimeUnit.SECONDS)
            .build()
        return response.newBuilder()
            .header("Cache-Control", cacheControl.toString())
            .build()
    }
}